package cn.fenqing168.springcloud.controller;

import cn.fenqing168.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    /**
     * 注入配置文件里的端口号
     */
    @Value("${server.port}")
    private String port;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfoOk(@PathVariable("id") Long id){
        String res = paymentService.paymentInfoOk(id);
        log.info("result:{}", res);
        return res;
    }

    /**
     * 超时的接口
     * @param id
     * @return
     */
    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfoTimeout(@PathVariable("id") Long id){
        String res = paymentService.paymentInfoTimeOut(id);
        log.info("result:{}", res);
        return res;
    }

    /**
     * @param id
     * @return
     */
    @GetMapping("/payment/circuit/{id}")
    public String circuit(@PathVariable("id") Long id){
        String res = paymentService.paymentCircutBreaker(id);
        log.info("result:{}", res);
        return res;
    }

}
